<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="begin">开始</button>
    <button class="stop">结束</button>
    <script>
        /* 需求 
        1. 点击开始按钮，启动定时器
        2. 点击停止按钮，停止定时器

        全局作用域不能访问局部作用域
        */
    var begin=document.querySelector('.begin');
    var stop=document.querySelector('.stop');
    var time1;

    begin.addEventListener('click',function(){
        console.log('开启定时器');
        time1=setInterval(() => {
            console.log('chijichiji');
        }, 1000);
    });
    stop.addEventListener('click',function(){
        console.log('停止定时器');
        clearInterval(time1);
    });
    </script>
</body>
</html>